package com.ruoyi.shopping.service.impl;

import java.sql.Wrapper;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.User;
import org.springframework.stereotype.Service;
import com.ruoyi.shopping.mapper.CommodityDeliveryAddressMapper;
import com.ruoyi.shopping.domain.CommodityDeliveryAddress;
import com.ruoyi.shopping.service.ICommodityDeliveryAddressService;

/**
 * 收货地址Service业务层处理
 *
 * @author ruoyi
 * @date 2024-08-14
 */
@Service
public class CommodityDeliveryAddressServiceImpl implements ICommodityDeliveryAddressService {
    @Autowired
    private CommodityDeliveryAddressMapper commodityDeliveryAddressMapper;

    /**
     * 查询收货地址
     *
     * @param id 收货地址主键
     * @return 收货地址
     */
    @Override
    public CommodityDeliveryAddress selectCommodityDeliveryAddressById(Long id) {
        return commodityDeliveryAddressMapper.selectCommodityDeliveryAddressById(id);
    }

    /**
     * 查询收货地址列表
     *
     * @param commodityDeliveryAddress 收货地址
     * @return 收货地址
     */
    @Override
    public List<CommodityDeliveryAddress> selectCommodityDeliveryAddressList(CommodityDeliveryAddress commodityDeliveryAddress) {
        return commodityDeliveryAddressMapper.selectCommodityDeliveryAddressList(commodityDeliveryAddress);
    }

    /**
     * 新增收货地址
     *
     * @param commodityDeliveryAddress 收货地址
     * @return 结果
     */
    @Override
    public int insertCommodityDeliveryAddress(CommodityDeliveryAddress commodityDeliveryAddress) {
        if (commodityDeliveryAddress.getStatus() == 1) {
            UpdateWrapper<CommodityDeliveryAddress> updateWrapper = new UpdateWrapper<>();
            updateWrapper.eq("status", 1);
            CommodityDeliveryAddress address = new CommodityDeliveryAddress();
            address.setStatus(0L);
            commodityDeliveryAddressMapper.update( address, updateWrapper);
        }
        return commodityDeliveryAddressMapper.insertCommodityDeliveryAddress(commodityDeliveryAddress);
    }

    /**
     * 修改收货地址
     *
     * @param commodityDeliveryAddress 收货地址
     * @return 结果
     */
    @Override
    public int updateCommodityDeliveryAddress(CommodityDeliveryAddress commodityDeliveryAddress) {
        return commodityDeliveryAddressMapper.updateCommodityDeliveryAddress(commodityDeliveryAddress);
    }

    /**
     * 批量删除收货地址
     *
     * @param ids 需要删除的收货地址主键
     * @return 结果
     */
    @Override
    public int deleteCommodityDeliveryAddressByIds(Long[] ids) {
        return commodityDeliveryAddressMapper.deleteCommodityDeliveryAddressByIds(ids);
    }

    /**
     * 删除收货地址信息
     *
     * @param id 收货地址主键
     * @return 结果
     */
    @Override
    public int deleteCommodityDeliveryAddressById(Long id) {
        return commodityDeliveryAddressMapper.deleteCommodityDeliveryAddressById(id);
    }
}
